package timing.ukulele.third.msgChannel.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import timing.ukulele.third.constant.MessageMqConstants;

@Configuration
public class OmsOrderRabbitMQConfig {


    //===========================普通交换机定义===========================

    /**
     * 定义普通交换机一
     * @return
     */
    @Bean
    public DirectExchange messageDirectExchangeOne() {
        return ExchangeBuilder.directExchange(MessageMqConstants.MESSAGE_NORMAL_DIRECT_EXCHANGE_ONE).build();
    }

    //===========================普通队列定义===========================

    /**
     * 定义普通队列
     * @return
     */
    @Bean
    public Queue messageDirectQueue() {
        // 使用 QueueBuilder 创建一个持久化队列
        return QueueBuilder.durable(MessageMqConstants.MESSAGE_SEND_DIRECT_QUEUE)
                .build();
    }

    /**
     * 将普通队列绑定到普通交换机一上面
     * @param messageDirectQueue
     * @param messageDirectExchangeOne
     * @return
     */
    @Bean
    public Binding bindingDirectExchangeByOrderExpireQueue(Queue messageDirectQueue, DirectExchange messageDirectExchangeOne) {
        return BindingBuilder.bind(messageDirectQueue).to(messageDirectExchangeOne).with(MessageMqConstants.MESSAGE_SEND_DIRECT_ROUTING_KEY);
    }

}
